package Model;

import java.io.Serializable;

/**
 * This class represents a Model.Car object
 * @author Matthew Page
 *         Date: 22/08/2010
 *         Time: 4:45:08 PM
 */
public class Car implements Serializable {
    private int rowLoc;
    private int colLoc;
    private int nextRowLoc;
    private int nextColLoc;
    private char direction;
    private char symbol;

    /**
     * Constructor
     */
    public Car(int rowLoc, int colLoc, char direction, char symbol) {
        this.rowLoc = rowLoc;
        this.colLoc = colLoc;
        this.nextRowLoc = rowLoc;
        this.nextColLoc = colLoc;
        this.direction = direction;
        this.symbol = symbol;
        switch (direction) {
            case 'N':
                this.nextRowLoc--;
                break;
            case 'S':
                this.nextRowLoc++;
                break;
            case 'E':
                this.nextColLoc++;
                break;
            case 'W':
                this.nextColLoc--;
                break;
        }
    }
    /**
     * Get row location.
     * @return rowLoc = Row Location
     *
     */
    public int getRowLoc() {
        return rowLoc;
    }
    /**
     * Set row location.
     * @param rowLoc = Row Location
     *
     */
    public void setRowLoc(int rowLoc) {
        this.rowLoc = rowLoc;
    }
    /**
     * Get col location.
     * @return colLoc = Column Location
     *
     */
    public int getColLoc() {
        return colLoc;
    }
    /**
     * Set column location.
     * @param colLoc = Column Location
     *
     */
    public void setColLoc(int colLoc) {
        this.colLoc = colLoc;
    }
    /**
     * Get car direction.
     * @return Char direction
     *
     */
    public char getDirection() {
        return direction;
    }
    /**
     * Set car direction.
     * @param direction = Character Model.Car direction
     *
     */
    public void setDirection(char direction) {
        this.direction = direction;
    }

    /**
     * Moves car.
     */
    public void move() {
        switch (direction) {
            case 'N':
                this.rowLoc--;
                this.nextRowLoc--;
                break;
            case 'S':
                this.rowLoc++;
                this.nextRowLoc++;
                break;
            case 'E':
                this.colLoc++;
                this.nextColLoc++;
                break;
            case 'W':
                this.colLoc--;
                this.nextColLoc--;
                break;
        }
    }

    /**
     * Tests methods in class Model.Car
     * @param args
     */
    public static void main(String[] args) {
        //This tests a method. Must be checked visually from output
        //Testing move and set methods
        Car c = new Car(0, 0, 'n', 'a');
        c.setRowLoc(10);
        c.setColLoc(10);
        c.setDirection('N');
        c.printDetails();
        c.move();
        c.printDetails();
        c.setDirection('S');
        c.printDetails();
        c.move();
        c.printDetails();
        c.setDirection('E');
        c.printDetails();
        c.move();
        c.printDetails();
        c.setDirection('W');
        c.printDetails();
        c.move();
        c.printDetails();
    }

    private void printDetails() {
        System.out.println("X Coord = " + this.rowLoc);
        System.out.println("Y Coord = " + this.colLoc);
        System.out.println("Direction = " + this.direction);
    }

    public int getNextRowLoc() {
        return this.nextRowLoc;
    }

    public void setNextRowLoc(int nextRowLoc) {
        this.nextRowLoc = nextRowLoc;
    }

    public int getNextColLoc() {
        return this.nextColLoc;
    }

    public void setNextColLoc(int nextColLoc) {
        this.nextColLoc = nextColLoc;
    }

    public char getSymbol() {
        return symbol;
    }
}
